package com.ruoyi.nlp.utils;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class SQLManager extends BaseDAO {



	// 验证是否有该关键词
	public boolean verificationGeneralWord(String wordName) {
		String sql = " select word_name from sys_general_word where word_name=? ";
		getConnection();
		boolean b = false;
		try {
			ps = con.prepareStatement(sql);
			ps.setString(1, wordName);
			ps.setString(2, wordName);
			rs = ps.executeQuery();
			while (rs.next()) {
				String r = rs.getString("word_name");
				if (r != null && !"".equals(r)) {
					b = true;
					break;
				}
			}
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		} finally {
			close();
		}
		return b;
	}

	// 验证是否有该关键词
	public boolean verificationThesauriWord(String wordName) {
		String sql = " select word_name from sys_thesauri_word where word_name=? ";
		getConnection();
		boolean b = false;
		try {
			ps = con.prepareStatement(sql);
			ps.setString(1, wordName);
			ps.setString(2, wordName);
			rs = ps.executeQuery();
			while (rs.next()) {
				String r = rs.getString("word_name");
				if (r != null && !"".equals(r)) {
					b = true;
					break;
				}
			}
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		} finally {
			close();
		}
		return b;
	}

	// 叙词表
	public List<String> getThesauriWord() {
		String sql = " select word_name,word_english from sys_thesauri_word ";
		getConnection();
		List<String> r = new ArrayList<String>();
		try {
			ps = con.prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {
				String word_name = rs.getString("word_name");
				if(word_name!=null) {
					word_name = word_name.toLowerCase();
				}
				String word_english = rs.getString("word_english");
				if(word_english!=null) {
					word_english = word_name.toLowerCase();
				}
				r.add(word_name + "≡" + word_english);
			}
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		} finally {
			close();
		}
		return r;
	}

	// 普通词表
	public List<String> getGeneralWord() {
		String sql = " select word_name,word_english from sys_general_word ";
		getConnection();
		List<String> r = new ArrayList<String>();
		try {
			ps = con.prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {
				String word_name = rs.getString("word_name");
				if(word_name!=null) {
					word_name = word_name.toLowerCase();
				}
				String word_english = rs.getString("word_english");
				if(word_english!=null) {
					word_english = word_name.toLowerCase();
				}
				r.add(word_name + "≡" + word_english);
			}
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		} finally {
			close();
		}
		return r;
	}

	public List<String> getNlpStopWord() {
		// TODO Auto-generated method stub
		String sql = " select word_name from sys_nlp_stop_word ";
		getConnection();
		List<String> r = new ArrayList<String>();
		try {
			ps = con.prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {
				String word_name = rs.getString("word_name");
				if(word_name!=null) {
					word_name = word_name.toLowerCase();
				}
				r.add(word_name);
			}
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		} finally {
			close();
		}
		return r;
	
	}

}
